<?php
class User_child_model extends CI_Model{

	/**
	 * 获取孩子信息
	 * @param  [type] $child_id [description]
	 * @return [type]           [description]
	 */
	function get_info_by_id($child_id){
		$sql = "SELECT * FROM {$this->db->dbprefix}user_childrens WHERE id = $child_id";
		return $this->db->query($sql)->row_array();
	}

	function get_habit_count($child_id){
		$sql = "SELECT COUNT(0) as habit_total FROM {$this->db->dbprefix}tasks  WHERE child_id = $child_id";
		return $this->db->query($sql)->row_array()['habit_total'];
	}

	function get_habit_by_child($child_id){
		$sql = "SELECT t.*,trs.id as statistics_id,trs.total_stars,trs.first_time,trs.last_time FROM {$this->db->dbprefix}tasks t 
		LEFT JOIN {$this->db->dbprefix}user_children_task_type_statistics trs on trs.task_id = t.id
		WHERE t.child_id = $child_id";
		return $this->db->query($sql)->result_array();
	}

	function get_habit_record($habit_id,$limit=3){
		$sql = "SELECT * FROM {$this->db->dbprefix}task_records 
		 WHERE task_id = $habit_id LIMIT $limit";

		return $this->db->query($sql)->result_array();
	}

	

}